package com.briup.app02.web.controller;

import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.app02.bean.Address;
import com.briup.app02.dao.AddressMapper;
import com.briup.app02.service.IAddressService;
import com.briup.app02.utils.Message;
import com.briup.app02.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Validated
@RestController
@RequestMapping("/address")
@Api(description="顾客地址相关接口")
public class AddressController {
	
	@Autowired
	private IAddressService addressService;
	
	@ApiOperation(value = "查询顾客地址相关信息")
	@GetMapping("query")
	@ApiImplicitParams({
		@ApiImplicitParam(name="name",value = "收件人",paramType = "query"),
	})
	public Message query(String name) {
		List<Address>list=addressService.query(name);
		return MessageUtil.success(list);
	}
	
	//分页查询
	@ApiOperation(value = "分页查询顾客地址相关信息")
	@ApiImplicitParams({
		  @ApiImplicitParam(name="page",value = "当前页",paramType = "query",required = true),
          @ApiImplicitParam(name="pageSize",value = "每页大小",paramType = "query",required = true),
          @ApiImplicitParam(name="userId",value = "用户编号",paramType = "query"),
	})
	@GetMapping("pageQuery")
	public Message pageQuery(int page,int pageSize,Long userId) {
		List<Address>list=addressService.pageQuery(page, pageSize, userId);
		return MessageUtil.success(list);
	}
	
	@ApiOperation(value = "通过id删除顾客信息")
	@GetMapping("deleteById")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
	})
	public Message deleteById( Long id) {
		addressService.deleteById(id);
		return MessageUtil.success("删除成功");
	}
	
	@ApiOperation(value = "保存或更新顾客信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value = "主键",paramType = "form"),
        @ApiImplicitParam(name="name",value = "收件人",paramType = "form"),
        @ApiImplicitParam(name="telephone",value = "手机号",paramType = "form"),
        @ApiImplicitParam(name="province",value = "省份",paramType = "form"),
        @ApiImplicitParam(name="city",value = "城市",paramType = "form"),
        @ApiImplicitParam(name="area",value = "区",paramType = "form"),
        @ApiImplicitParam(name="address",value = "详细地址",paramType = "form"),
        @ApiImplicitParam(name="isDefault",value = "是否默认",paramType = "form"),
        @ApiImplicitParam(name="userId",value = "用户编号",paramType = "form"),
	})
	@PostMapping("saveOrUpdate")
	public Message saveOrUpdate(Address address) {
		addressService.saveOrUpdate(address);
		return MessageUtil.success("更新成功");
	}
	
}	
	/*@GetMapping("selectById")
	@ApiOperation("根据id查询顾客地址")
	@ApiImplicitParam(name ="id",value = "顾客id",dataType = "long",paramType = "query",required = true)
	public Address findById(long id) {
		return addressService.findById(id);
	}
	
	@PostMapping("saveOrUpdate")
	@ApiOperation(value="保存或更新",notes = "id为空是保存否则是更新")
	public String saveOrUpdate(Address address) {
		addressService.saveOrUpdate(address);
		return "操作成功";
	}
	
	@DeleteMapping("deleteById")
	@ApiOperation("根据id删除顾客地址")
	@ApiImplicitParam(name="id",value = "栏目id",dataType = "long",paramType = "query",required = true)
	public String deleteById(long id) {
		addressService.deleteById(id);
		return "删除成功";
	}*/

